﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Toom.CellularAutomata.Model.Fast
{


	public abstract class CARuleFast : CAExpressionFast
	{
		//protected CAField field;
		protected List<CAExpressionFast> args;


		public void SpecifyArguments(List<CAExpressionFast> args)
		{
			// copy vectors
			this.args = new List<CAExpressionFast>(args.Count);
			this.args.AddRange(args);
		}


		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("This is a CARuleMedian with args");

			foreach (CAExpressionFast e in args)
			{
				if (e is CAVectorFast)
				{
					sb.Append(" vector ");
					sb.Append(e.ToString());
				}
				else if (e is CAExpressionFast)
				{
					sb.Append(" expr ");
					sb.Append(e.ToString());
				}
				else
				{
					sb.Append(" ??? ");
					sb.Append(e.ToString());
				}

			}

			sb.Append(".");

			return sb.ToString();
		}
	}



	//public class CARuleMedian : CARule
	//{
	//	public CARuleMedian()
	//	{
	//	}

	//	public override int Evaluate(CAField field, CAPoint p)
	//	{
	//		// check that list of args is non-empty
	//		if (args.Count == 0)
	//			throw new Exception("empty list of args in CARuleMedian.Evaluate");

	//		int[] values = new int[MAX_ARRAY_SIZE];
	//		int valuesIdx = 0;

	//		foreach ( CAExpression e in args )
	//		{
	//			values[valuesIdx++] = e.Evaluate(field, p);
	//		}

	//		Array.Sort(values);
	//		int indexMid = valuesIdx / 2;

	//		return values[indexMid];
	//	}

	//}//class CARuleMedian 



	//public class CARuleMaximum : CARule
	//{
	//	public CARuleMaximum()
	//	{
	//	}

	//	public override int Evaluate(CAField field, CAPoint p)
	//	{
	//		// check that list of args is non-empty
	//		if (args.Count == 0)
	//			throw new Exception("empty list of args in CARuleMaximum.Evaluate");

	//		int max = int.MinValue;

	//		foreach (CAExpression e in args)
	//		{
	//			int v = e.Evaluate(field, p);
	//			if (v > max)
	//				max = v;
	//		}

	//		return max;
	//	}
	//}//class CARuleMaximum 



	//public class CARuleMinimum : CARule
	//{
	//	public CARuleMinimum()
	//	{
	//	}

	//	public override int Evaluate(CAField field, CAPoint p)
	//	{
	//		// check that list of args is non-empty
	//		if (args.Count == 0)
	//			throw new Exception("empty list of args in CARuleMaximum.Evaluate");

	//		int min = int.MaxValue;

	//		foreach (CAExpression e in args)
	//		{
	//			int v = e.Evaluate(field, p);
	//			if (v < min)
	//				min = v;
	//		}

	//		return min;
	//	}
	//}//class CARuleMinimum 


}//ns
